
//
//  SYInvitelINKCell.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2017/11/21.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDInvitelinkCell.h"

@interface YDInvitelinkCell()

//邀请图片
@property (nonatomic , weak) UIImageView *qrImageView;
//二维码背后图片
@property (nonatomic , weak) UIImageView *qrBackImage;
//邀请码label
@property (nonatomic , weak) UILabel *qrButton;
//专属邀请码
@property (nonatomic , weak) UILabel *exclusiveLabel;
//
@property (nonatomic , weak) UILabel *detailLabel1;
@property (nonatomic , weak) UILabel *detailLabel2;
@end


@implementation YDInvitelinkCell

-(void)setDict:(NSDictionary *)dict
{
    _dict = dict;
    //获取邀请码
    NSString *qrCodeString = [NSString stringWithFormat:@"%@" , dict[@"promotionCode"]];
    self.qrButton.text = qrCodeString;
}

+ (instancetype)cellWithTableview:(UITableView *)tableView
{
    static NSString *myMemberCell = @"SYInvitelINKCell";
    YDInvitelinkCell *cell = [tableView dequeueReusableCellWithIdentifier:myMemberCell];
    if (cell == nil) {
        cell = [[YDInvitelinkCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myMemberCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        self.backgroundColor = [UIColor whiteColor];
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self qrImageView];
//        [self qrBackImage];
        [self qrButton];
        [self exclusiveLabel];
        [self detailLabel1];
        [self detailLabel2];
    }
    return self;
}

-(UIImageView *)qrImageView
{
    if (_qrImageView == nil) {
        UIImageView *qrImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:qrImageView];
        qrImageView.backgroundColor = [UIColor clearColor];
        qrImageView.image = [UIImage imageNamed:@"wd-yaoqingma"];
        [qrImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(60));
                make.height.equalTo(@(rateX812(86)));
            }else{
                make.top.equalTo(self).offset(rate750(60));
                make.height.equalTo(@(rate750(86)));
            }
            make.width.equalTo(@(rate375(206)));
            
        }];
        _qrImageView = qrImageView;
    }
    return _qrImageView;
}

-(UIImageView *)qrBackImage
{
    if (_qrBackImage == nil) {
        UIImageView *qrBackImage = [[UIImageView alloc] init];
        [self.contentView addSubview:qrBackImage];
        qrBackImage.userInteractionEnabled = YES;
        qrBackImage.backgroundColor = [UIColor clearColor];
        qrBackImage.image = [UIImage imageNamed:@"wd-yaoqingma-shurukuang"];
        [qrBackImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.qrImageView);
            make.width.equalTo(@(rate375(112)));
            make.left.equalTo(self).offset(rate375(154));
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(44)));
            }else{
                make.height.equalTo(@(rate750(44)));
            }
        }];
        
        _qrBackImage = qrBackImage;
    }
    return _qrBackImage;
}

-(UILabel *)qrButton
{
    if (_qrButton == nil) {
        UILabel *qrButton = [[UILabel alloc] init];
        [self.contentView addSubview:qrButton];
        qrButton.backgroundColor = NumberColor(249, 249, 249);
        qrButton.textColor = [UIColor colorWithHexString:paleRed];
        qrButton.font = [UIFont systemFontOfSize:font24ScreenWRate * LKScreenW];
        qrButton.textAlignment = NSTextAlignmentCenter;
        //wd-yaoqingma-shurukuang
        qrButton.text = @"123456";
        [qrButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.qrImageView);
            make.width.equalTo(@(rate375(112)));
            make.left.equalTo(self).offset(rate375(154));
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(44)));
            }else{
                make.height.equalTo(@(rate750(44)));
            }
        }];
        qrButton.userInteractionEnabled = YES;
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressGesture:)];
        [qrButton addGestureRecognizer:longPress];
        
        
        _qrButton = qrButton;
    }
    return _qrButton;
}
- (void)LongPressGesture:(UILongPressGestureRecognizer *)longPress
{
    if (longPress.state == UIGestureRecognizerStateBegan) {
        
        UIPasteboard *pBoard = [UIPasteboard generalPasteboard];
        pBoard.string = self.qrButton.text;
        if (pBoard.string.length && [self.delegate respondsToSelector:@selector(invitelinkCellDidPastedInvitelinkCode:)]) {
            [self.delegate invitelinkCellDidPastedInvitelinkCode:pBoard.string];
        }
        
        
    }
}

-(UILabel *)exclusiveLabel
{
    if (_exclusiveLabel == nil) {
        UILabel *exclusiveLabel = [[UILabel alloc] init];
        [self.contentView addSubview:exclusiveLabel];
        exclusiveLabel.backgroundColor = [UIColor clearColor];
        exclusiveLabel.textColor = NumberColor(62, 89, 167);
        exclusiveLabel.textAlignment = NSTextAlignmentCenter;
        exclusiveLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        exclusiveLabel.text = @"专属邀请码，只告诉亲密的人哟~";
        [exclusiveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            if (isPhoneX) {
                make.top.equalTo(self.qrImageView.mas_bottom).offset(rateX812(20));
            }else{
                make.top.equalTo(self.qrImageView.mas_bottom).offset(rate750(20));
            }
        }];
        exclusiveLabel.adjustsFontSizeToFitWidth = YES;
        _exclusiveLabel = exclusiveLabel;
    }
    return _exclusiveLabel;
}

-(UILabel *)detailLabel1
{
    if (_detailLabel1 == nil) {
        UILabel *detailLabel1 = [[UILabel alloc] init];
        [self.contentView addSubview:detailLabel1];//blueyGrey
        detailLabel1.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        detailLabel1.textColor = NumberColor(104, 114, 132);
        detailLabel1.textAlignment = NSTextAlignmentLeft;
        detailLabel1.numberOfLines = 0;
        [detailLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.width.equalTo(@(rate375(259)));
            if (isPhoneX) {
                make.top.equalTo(self.exclusiveLabel.mas_bottom).offset(rateX812(60));
            }else{
                make.top.equalTo(self.exclusiveLabel.mas_bottom).offset(rate750(60));
            }
        }];
        NSString *string = @"1、这是你的专属邀请码，分享给你的朋友；\n2、你的朋友在注册<优股网>时填写邀请码，将成为你的关联用户；\n3、当关联用户第一次进行点买交易结算后，你将获得此单信息服务费的10%，可以在已赚佣金中查看；";
        
        NSAttributedString *attr = [NSString createLineWrapAttriStringWithString:string andLineSpace:2.0 withWrapSpace:0.3 Font:[UIFont systemFontOfSize:font12ScreenWRate * LKScreenW]];
        
        detailLabel1.attributedText = attr;
        
        _detailLabel1 = detailLabel1;
    }
    return _detailLabel1;
}
-(UILabel *)detailLabel2
{
    if (_detailLabel2 == nil) {
        UILabel *detailLabel2 = [[UILabel alloc] init];
        [self.contentView addSubview:detailLabel2];
        detailLabel2.backgroundColor = [UIColor clearColor];
        detailLabel2.textColor = [UIColor colorWithHexString:paleRed];
        detailLabel2.textAlignment = NSTextAlignmentCenter;
        detailLabel2.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        detailLabel2.text = @"分享给好友一起赚钱吧~";
        [detailLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            if (isPhoneX) {
                make.top.equalTo(self.detailLabel1.mas_bottom).offset(rateX812(25));
            }else{
                make.top.equalTo(self.detailLabel1.mas_bottom).offset(rate750(25));
            }
        }];
        detailLabel2.adjustsFontSizeToFitWidth = YES;
        _detailLabel2 = detailLabel2;
    }
    return _detailLabel2;
}

@end
